package com.chainyoung.component_tmmarket.mvp.presenter;

import com.chainyoung.common.base.CommonSubscriber;
import com.chainyoung.common.bean.UserInfo;
import com.chainyoung.common.di.scope.FragmentScope;
import com.chainyoung.common.mvp.BasePresenter;
import com.chainyoung.common.utils.RxUtils;
import com.chainyoung.component_tmmarket.bean.MarketList;
import com.chainyoung.component_tmmarket.mvp.contract.MarketMainContract;

import java.util.List;
import java.util.TreeMap;

import javax.inject.Inject;



public class MarketMainPresenter extends BasePresenter<MarketMainContract.Model, MarketMainContract.View> {

    @Inject
    public MarketMainPresenter(MarketMainContract.Model model, MarketMainContract.View view) {
        super(model, view);
    }


    public void getMarketCurrencys() {
        addSubscribe(
                mModel.getMarketCurrencys()
                        .compose(RxUtils.<MarketList>rxSchedulerHelper())
                        .subscribeWith(new CommonSubscriber<MarketList>(mView,true) {
                            @Override
                            public void onNext(MarketList data) {
                                mView.showMarketCurrencys(data);
                            }

                            @Override
                            public void onError(Throwable e) {
                                mView.onGetMarketCurrencysFailed();
                                super.onError(e);
                            }
                        })
        );
    }

    public void getUserInfo(TreeMap<String, Object> map) {
        addSubscribe(mModel.getUserInfo(map)
                .compose(RxUtils.<UserInfo>rxSchedulerHelper())
                .subscribeWith(new CommonSubscriber<UserInfo>(mView) {
                    @Override
                    public void onNext(UserInfo object) {
                        mView.onGetUserInfoSuccess(object);
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                    }
                }));
    }




}
